package edu.guet.server.controller;

import edu.guet.server.model.Comment;
import edu.guet.server.model.Post;
import edu.guet.server.service.CommentService;
import edu.guet.server.service.PostService;
import edu.guet.server.utils.ResultAPI;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;

@RestController
@Slf4j
@RequestMapping("/post")
public class PostController {

    @Autowired
    PostService postService;
    @Autowired
    private CommentService commentService;

    //返回头像和用户名
    //最新评论显示出来

    @GetMapping("/hot")//按评论数量排序post
    public ResultAPI hottestComment() {
        return postService.hottestPost();
    }

    @GetMapping("/new")//按评论时间排序post
    public ResultAPI newestComment() {
        return postService.newestPost();
    }

    @GetMapping("/getPost")
    public ResultAPI getPost(@RequestParam Integer semester_id) {
        return postService.getPost(semester_id);
    }

    @PostMapping("/setPost")
    public ResultAPI setPost(@RequestBody Post post) {
        return postService.setPost(post);
    }

    /**
     * 其实是有关comment的，该教师发布的课程话题回复
     * @param semester_id
     * @param publisher_id
     * @return
     */
    @GetMapping("/TechReply")
    public ResultAPI getTechReply(@RequestParam Integer semester_id, @RequestParam Integer publisher_id) {
        return postService.getPostReply(semester_id,publisher_id);
    }
    @DeleteMapping("/deleteReply")
    public ResultAPI deleteReply(@RequestParam Integer comment_id) {
        Comment comment=new Comment();
        comment.setComment_id(comment_id);
        return commentService.deleteComment(comment);
    }
}


